package com.yingsheng.bi.hks.service.categories;

import com.yingsheng.bi.hks.bo.CategoriesBo;
import com.yingsheng.bi.hks.dto.categories.*;
import com.yingsheng.bi.hks.mapping.CategoriesMgmtMappings;
import com.yingsheng.bi.hks.repository.dao.po.Categories;
import com.yingsheng.bi.hks.repository.dao.service.CategoriesDaoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class CategoriesMgmtService {

    @Autowired
    private CategoriesDaoService categoriesDaoService;

    /**
     * 收件信息新增
     * @param req
     * @return
     */
    public CategoriesAddRes add(CategoriesAddReq req) {
        Categories categories = CategoriesMgmtMappings.INSTANCE.addReq2po(req);
        categoriesDaoService.insert(categories);
        return new CategoriesAddRes();
    }

    public CategoriesModRes mod(CategoriesModReq req) {
        Categories categories = CategoriesMgmtMappings.INSTANCE.addReq2po(req);
        categoriesDaoService.updateById(categories);
        return new CategoriesModRes();
    }

    public CategoriesQryRes qry(CategoriesQryReq req) {
        List<Categories> list = categoriesDaoService.query(req);
        List<CategoriesBo> categoriesBoList = CategoriesMgmtMappings.INSTANCE.categoriesList2boList(list);
        CategoriesQryRes res = new CategoriesQryRes();
        res.setCategoriesBoList(categoriesBoList);
        return res;
    }

    public CategoriesDelRes del(CategoriesDelReq req) {
        categoriesDaoService.del(req.getId());
        CategoriesDelRes res = new CategoriesDelRes();
        return res;
    }
}
